package com.tsing.mapper.impl;

import com.tsing.common.framwork.mapper.CommonDao;
import com.tsing.mapper.LoveMapper;
import com.tsing.pojo.entity.TlLove;

import java.sql.SQLException;
import java.util.List;

/**
 * @auth 卢孝宇
 * @date 2023/12/10 16:13
 */
public class LoveMapperImpl  extends CommonDao implements LoveMapper {
    @Override
    public List<TlLove> loveCount(Long userId, Long postId) {
        List<TlLove> list = null;

        Object[] params = {userId,postId};
        try {
            list = executeQuery(TlLove.class, "select * from tl_love where userId = ? and postId = ?",params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public Integer add(Integer userId, Integer postId) {
        Integer list = null;

        Object[] params = {userId,postId};
        try {
            list = executeUpdate("insert into tl_love(userId,postId) values(?,?)",params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public Integer delete(Integer userId, Integer postId) {
        Integer list = null;

        Object[] params = {userId,postId};
        try {
            list = executeUpdate("delete from tl_love where userId = ? and postId = ?",params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
